<template>
<div id="help">
    <!-- 页头 -->
    <PageHeader :lang="lang"></PageHeader>
    <!-- 搜索 -->
    <search></search>
    <!-- 问题类型 -->
    <div class="question-type">
      <div class="item" v-for="item in classList">
        <div class="title" @click="toJump('hlist', item.ID)">{{item.title}}</div>
        <div class="list" v-for="caption in item.HelpsList">
          <a href="javascript:;" @click="toJump('hdetail', caption.ID)">
            {{caption.Title}}
          </a>
        </div>
        <a class="more-btn" href="javascript:;" @click="toJump('hlist', item.ID)">
          {{ lang.indexMore }} >>
        </a>
      </div>
    </div>
    <!-- 常见问题 -->
    <div class="common-problem">
      <div class="title" v-text="lang.helpCommonProblem"></div>
      <div class="list">
        <div class="item" v-for="item in recommendList">
          <a href="javascript:;" @click="toJump('hdetail', item.ID)">
            {{item.Title}}
          </a>
        </div>
      </div>
    </div>
    <!-- 页脚 -->
    <PageFooter2 :lang="lang" :langKey="langKey"></PageFooter2>
</div>
</template>

<script>
import commonMixins from '@/mixins/common.js'
import Search from './search.vue'

export default {
  mixins: [commonMixins],
  data () {
    return {
      classList: [],
      caption: [],
      recommendList: []
    }
  },
  components: {
    Search
  },
  watch: {
    langKey () {
      let lk = window.localStorage.getItem('langKey')
      this.langkey = lk === 'zh-CN' ? 'zh-CN' : 'en'
      this.getProblemType()
      this.getCommonProblem()
    }
  },
  methods: {
    init () {
      var self = this
      if (window.localStorage) {
        var lkey = window.localStorage.getItem('langKey')
        if (lkey) {
          self.langkey = lkey === 'zh-CN' ? 'zh-CN' : 'en'
        } else {
          self.langkey = 'zh-CN'
          window.localStorage.setItem('langKey', self.langkey)
        }
      }
    },
    // 获取问题类型
    getProblemType () {
      this.$http.post('FHelpsClass/GetList', {
        LanguageType: this.langKey,
        pageIndex: 0,
        pageSize: 12
      }).then((s) => {
        this.classList = s.Data
      })
    },
    // 获取常见问题
    getCommonProblem () {
      this.$http.post('Helps/GetRecommendList', {
        LanguageType: this.langKey,
        helpsTypeID: '',
        pageIndex: 0,
        pageSize: 6
      }).then((res) => {
        this.recommendList = res.Data
      })
    },
    // 带参跳转详情页
    toJump (name, id) {
      this.$router.push({
        name: name,
        params: {
          id: id
        }
      })
    }
  },
  mounted () {
    this.init()
    this.getProblemType()
    this.getCommonProblem()
  }
}
</script>

<style lang="less">
#help {
  color: #fff;

  .question-type {
    width: 1200px;
    margin: 0 auto;
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    flex-wrap: wrap;

    .item {
      width: 450px;
      margin-top: 50px;
      display: flex;
      flex-direction: column;

      .title {
        width: auto;
        min-width: 170px;
        max-width: 100%;
        padding: 16px 20px;
        box-sizing: border-box;
        border: 1px solid #3782FF;
        border-radius: 4px;
        text-align: center;
        font-size: 16px;
        align-self: baseline;
        text-overflow: ellipsis;
        overflow: hidden;
        cursor: pointer;

        &:hover {
          background-color: #357BF0;
        }
      }
      .list {
        a {
          display: block;
          padding: 22px 0 14px 0;
          border-bottom: 1px solid #3B404B;
          color: #ccc;
        }
      }
      .more-btn {
        height: 36px;
        line-height: 36px;
        text-align: right;
        font-size: 14px;
        color: #3782FF;
        cursor: pointer;
      }
    }
  }

  .common-problem {
    width: 1200px;
    margin: 50px auto 30px auto;

    .title {
        font-size: 20px;
    }
    .list {
      display: flex;
      flex-direction: row;
      justify-content: flex-start;
      flex-wrap: wrap;
      margin-top: 30px;

      .item {
        width: 28%;
        margin: 0 80px 30px 0;
        padding-bottom: 16px;
        box-sizing: border-box;
        border-bottom: 1px solid #3B404B;

        a {
          color: #ccc;
        }
      }
      .item:nth-child(3n) {
          margin-right: 0;
      }
    }
  }

  /*== 800px ==*/
  @media only screen and (max-width: 1200px) {
    .question-type {
      width: 730px;

      .item {
        width: 42%;
      }
    }
    .common-problem {
      width: 730px;
    }
  }
}
</style>
